package training;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_6_22_Training {
    //将字符串拆分为若干长度为 k 的组
    public String[] divideString(String s, int k, char fill) {
        int len = s.length();
        int size = len%k==0?len/k:(len/k)+1;
        String[] ans = new String[size];
        StringBuilder  sb = new StringBuilder();
        for(int i=0;i<len;i++){
            sb.append(s.charAt(i));
            if(sb.length()==k){
                ans[((i+1)/k)-1] = sb.toString();
                sb = new StringBuilder();
            }
        }
        if(sb.length()!=0&&  sb.length()<k){
            while(sb.length()!=k){
                sb.append(fill);
            }
            ans[size-1] = sb.toString();
        }
        return ans;
    }
}
